SPB Git

Repository Public

route.ts 3.4 KB 93 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : SPB Private Cloud8 * File             : app/api/shares/[id]/route.ts9 * Module           : app10 * Repository       : https://git.spboucher.ai/spb-cloud11 * Project Website  : https://cloud.spboucher.ai12 * Created          : 2026-02-1813 * Last Modified    : 2026-09-0714 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: admin@spboucher.ai23 * Technical Contact: dev@spboucher.ai24 * Security/Admin   : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License          : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142import { NextRequest, NextResponse } from "next/server";43import { prisma } from "@/lib/prisma";44import { logActivity } from "@/lib/activity";45import bcrypt from "bcryptjs";4647export async function PATCH(48  request: NextRequest,49  { params }: { params: { id: string } }50) {51  const body = await request.json().catch(() => ({}));52  const { active, expiresAt, password, mode } = body as { active?: boolean; expiresAt?: string | null; password?: string | null; mode?: string };5354  const existing = await prisma.sharedLink.findUnique({ where: { id: params.id } });55  if (!existing) return NextResponse.json({ error: "Share not found" }, { status: 404 });5657  const data: Record<string, unknown> = {};58  if (typeof active === "boolean") data.active = active;59  if (expiresAt !== undefined) {60    if (expiresAt === null || expiresAt === "") data.expiresAt = null;61    else {62      const d = new Date(expiresAt);63      if (isNaN(d.getTime())) return NextResponse.json({ error: "Date invalide" }, { status: 400 });64      data.expiresAt = d;65    }66  }67  if (password !== undefined) data.passwordHash = password ? await bcrypt.hash(password, 10) : null;68  if (mode === "PREVIEW" || mode === "DOWNLOAD") data.mode = mode;6970  const share = await prisma.sharedLink.update({ where: { id: params.id }, data });7172  if (active === false) {73    await logActivity("UNSHARE", share.fileId, "Link deactivated");74  }7576  return NextResponse.json(share);77}7879export async function DELETE(80  request: NextRequest,81  { params }: { params: { id: string } }82) {83  const share = await prisma.sharedLink.findUnique({ where: { id: params.id } });84  if (!share) {85    return NextResponse.json({ error: "Share not found" }, { status: 404 });86  }8788  await prisma.sharedLink.delete({ where: { id: params.id } });89  await logActivity("UNSHARE", share.fileId, "Link deleted");9091  return NextResponse.json({ success: true });92}93
Files main
Menu

Theme